#include<bits/stdc++.h>
using namespace std;
#define int long long
#define getchar() (p1 == p2 && (p2 = (p1 = buf1) + fread(buf1, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf1[1 << 23], *p1 = buf1, *p2 = buf1, ubuf[1 << 23], *u = ubuf;
namespace IO
{
	template<typename T>
	void read(T &_x){_x=0;int _f=1;char ch=getchar();while(!isdigit(ch)) _f=(ch=='-'?-1:_f),ch=getchar();while(isdigit(ch)) _x=_x*10+(ch^48),ch=getchar();_x*=_f;}
	template<typename T,typename... Args>
	void read(T &_x,Args&...others){Read(_x);Read(others...);}
	const int BUF=20000000;char buf[BUF],to,stk[32];int plen;
	#define pc(x) buf[plen++]=x
	#define flush(); fwrite(buf,1,plen,stdout),plen=0;
	template<typename T>inline void print(T x){if(!x){pc(48);return;}if(x<0) x=-x,pc('-');for(;x;x/=10) stk[++to]=48+x%10;while(to) pc(stk[to--]);}
}
using namespace IO;
const int N = 5010,mod = 1e9+7;
int n,k,a[N],l[N],head[N],x,y,cnt,v1[N],f[N][N],ans;
vector<int>v[N];
struct w
{
	int to,nxt;
}b[N<<1];
inline void add(int x,int y)
{
	b[++cnt].nxt = head[x];
	b[cnt].to = y;
	head[x] = cnt;
}
signed main()
{
	freopen("water.in","r",stdin);
	freopen("water.out","w",stdout);
	read(n),read(k);
	for(int i = 1;i <= k;i++) read(a[i]);
	for(int i = 1;i <= n;i++)
	{
		read(l[i]); v[i].push_back(0);
		for(int j = 1;j <= l[i];j++) read(x),v[i].push_back(x);
	}
	for(int i = 1;i < n;i++) read(x),read(y),add(x,y),add(y,x);
	f[1][1] = 1;
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= i;j++)
			{
				f[i+1][j] = (f[i+1][j]+f[i][j]*i)%mod;
				f[i+1][j+1] = (f[i+1][j+1]+f[i][j])%mod;
			}
		for(int i = 1;i <= n;i++) ans = (ans+f[n][i])%mod;
		print(ans*a[1]%mod); flush();
	return 0;
}

